package com.nbsaas.sample.user.rest.convert;

import com.nbsaas.sample.entity.user.Structure;
import com.nbsaas.sample.user.api.domain.simple.StructureSimple;

import com.nbsaas.boot.rest.api.Converter;
import java.util.stream.Collectors;
import lombok.Data;
/**
* 列表对象转换器
*/

@Data
public class StructureSimpleConvert implements Converter<StructureSimple, Structure> {


        private int fetch;


    @Override
    public StructureSimple convert(Structure source) {
        StructureSimple result = new StructureSimple();

                    if(source.getParent()!=null){
                    result.setParent(source.getParent().getId());
                    }
                    if(source.getParent()!=null){
                    result.setParentName(source.getParent().getName());
                    }
                    result.setId(source.getId());
                    result.setRgt(source.getRgt());
                    result.setLevelInfo(source.getLevelInfo());
                    result.setIds(source.getIds());
                    result.setLastDate(source.getLastDate());
                    result.setSortNum(source.getSortNum());
                    result.setLft(source.getLft());
                    result.setAddDate(source.getAddDate());
                    result.setName(source.getName());
                    result.setCode(source.getCode());

            result.setLabel(source.getName());
            result.setValue(""+source.getId());
            if (source.getChildren()!=null&&source.getChildren().size()>0){
                if (fetch!=0){
                    result.setChildren(source.getChildren().stream().map(this).collect(Collectors.toList()));
                }
            }

    return result;
  }

}